<template>
  <div class="y-w-full y-h-full y-flex">
    <el-input v-model="captchaCode" :placeholder="placeholder"></el-input>
    <div class="y-h-full y-pl-2 y-cursor-pointer">
      <el-image :src="imgBase" @click="getCaptchaInfo" class="y-whitespace-nowrap"></el-image>
    </div>
  </div>
</template>

<script>
export default {
  name: "captcha",
  props: {
    placeholder: {
      type: String,
      default: "请输入验证码",
    },
    value: {
      type: String,
      default: "",
    },
  },
  computed: {
    captchaCode: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
  },
  data() {
    return {
      imgBase: "",
    };
  },
  methods: {
    async getCaptchaInfo() {
      try {
        let res = await this.$globalApi.login.getCaptchaApi();
        this.imgBase  = res.img;
      } catch (err) {
        console.log('获取验证码错误了', err);
      }
    },
  },
  mounted() {
    this.getCaptchaInfo();
  },
};
</script>

<style lang="scss" scoped>
</style>
